package io.renren.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ch --x
 * @version 1.0
 * Create by 2024/1/15 15:42
 * @ClassName WxMaConfig
 * @Description todo
 */
@Configuration
@EnableConfigurationProperties(WxMaProperties.class)
public class WxMaConfig {
    @Autowired
    private WxMaProperties wxMaProperties;

    /**
     * 初始化微信服务 会自动维护获取access_token
     * @return
     */
    @Bean
    public WxMaService wxMaService() {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(wxMaProperties.getAppid());
        config.setSecret(wxMaProperties.getSecret());
        WxMaService service = new WxMaServiceImpl();
        service.setWxMaConfig(config);
        return service;
    }
}